<template>
    <div class="home-page">
        <section class="py-5 text-center container">
        <div class="row py-lg-5">
            <div class="col-lg-6 col-md-8 mx-auto">
            <img src="../assets/callout.svg" alt="callout" class="w-50"/>
            <h2 class="font-weight-light">随心写作，自由表达</h2>
            <p>
                <RouterLink to="/create" class="btn btn-primary my-2">开始写文章</RouterLink>
            </p>
            </div>
        </div>
        </section>
        <h4 class="font-weight-bold text-center">发现精彩</h4>
        <ColumnList :columns="columns"></ColumnList>
    </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useStore } from 'vuex'
import { GlobalDataProps, ResponseType, ImageProps } from '../store'
import ColumnList from '../components/ColumnList.vue'
import { RouterLink } from 'vue-router'
import createMessage from '../components/createMessage'

const store = useStore<GlobalDataProps>()
onMounted(() => {
    store.dispatch('fetchColumns')
})
const columns = computed(() => store.state.columns)

const beforeUpload = (file: File) => {
    if (file.type === 'image/jpeg' || file.type === 'image/png') {
        return true
    } else {
        createMessage('请上传jpg或者png格式的图片', 'danger')
        return false
    }
}
const onFileUploaded = (rawData: ResponseType<ImageProps>) => {
    createMessage(`上传成功 ${rawData.data._id}`, 'success')
}
const onFileUploadedError = (rawData: ResponseType<ImageProps>) => {
    createMessage(`上传失败 ${rawData.data._id}`, 'danger')
}
</script>